package com.hp.webchat.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hp.webchat.domain.User;

@Controller
@RequestMapping("/")
public class IndexController {
    @RequestMapping("index")
    public String index(
	    HttpServletRequest request,
	    @RequestParam(required=true) String name, 
	    ModelMap model){
	List<String> pigs = new ArrayList<String>();
	for(int i = 0; i < 10; i++){
	    pigs.add("pig "+i+" "+name);
	}
	model.addAttribute("pigs", pigs);
	model.addAttribute("name", name);
	return "index";
    }
    
    
    
    @RequestMapping("display")    
    public @ResponseBody User displayUser(
    		@RequestParam(required=true) String name, 
    		@RequestParam(required=true) int age) {
    	return new User(name, age);
    }
}
